﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Permissions;
using System.Runtime.Serialization;

namespace NBusiness.Data
{
    public class ModelErrorException : Exception
    {
        private Exception _originalException;

        public Exception OriginalException
        {
            get { return _originalException; }
        }

        public ModelErrorException() { }

        public ModelErrorException(string message)
            : base(message)
        { }

        public ModelErrorException(string message, Exception innerException)
            : base(message, innerException)
        { }

        protected ModelErrorException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        { }

        public ModelErrorException(string message, Exception innerException, Exception originalException)
            : base(message, innerException)
        {
            _originalException = originalException;
        }

        public ModelErrorException(Exception innerException, Exception originalException)
            : base(null, innerException)
        {
            _originalException = originalException;
        }

        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
                throw new ArgumentNullException("Resources.CompilationExceptionInfoParam", "Resources.CompilationExceptionInfoNullMessage");

            info.AddValue("_originalException", _originalException, _originalException.GetType());

            base.GetObjectData(info, context);
        }
    }
}
